package com.invokestatic.shooter;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class Art {
	
	public static boolean loaded = false;
	public static boolean loading = false;
	
	public static TextureRegion[][] font;
	public static TextureRegion[][][] players;
	public static TextureRegion splashscreen_bg;
	public static TextureRegion menu_bg;
	public static TextureRegion[][] walls;
	public static Pixmap[] maps_ctf;
	
	public static void preload() {
		font = split("res/font.png",16,16, false);
		splashscreen_bg = load("res/splashscreen_bg.png", 1280, 720);
	}
	
	public static void load() {
		loading = true;
		menu_bg = load("res/background.png", 1280, 720);
		maps_ctf = new Pixmap[1];
//		maps_ctf[0].getP
		maps_ctf[0] = new Pixmap(Gdx.files.internal("res/ctf_1.png"));
		players = new TextureRegion[1][3][2];
		for(int i = 0; i < 1; i++) {
			players[i] = split("res/player.png", 32, 32);
		}
		walls = split("res/walls.png", 8, 8);
		loaded = true;
	}
	
	private static TextureRegion[][] split (String name, int width, int height) {
		return split(name, width, height, false);
	}

	private static TextureRegion[][] split (String name, int width, int height, boolean flipX) {
		Texture texture = new Texture(Gdx.files.internal(name));
		int xSlices = texture.getWidth() / width;
		System.out.println(xSlices);
		int ySlices = texture.getHeight() / height;
		TextureRegion[][] res = new TextureRegion[xSlices][ySlices];
		for (int x = 0; x < xSlices; x++) {
			for (int y = 0; y < ySlices; y++) {
				res[x][y] = new TextureRegion(texture, x * width, y * height, width, height);
				res[x][y].flip(flipX, true);
			}
		}
		return res;
	}

	public static TextureRegion load (String name, int width, int height) {
		Texture texture = new Texture(Gdx.files.internal(name));
		TextureRegion region = new TextureRegion(texture, 0, 0, width, height);
		region.flip(false, true);
		return region;
	}
}
